<style>
    .w-120 {
        width: 115px;
    }

    .conentStyle {
        padding: 10px;
        box-sizing: border-box;
    }

    .conentBg {
        padding: 20px;
        box-sizing: border-box;
        border-radius: 5px;
        background-color: #fff;
        min-height: 660px;
    }

    .borderNone {
        border: none;
    }

    .formBg {
        background-color: #F7F8FA;
        padding: 20px;
    }

    .layui-table-cell {
        height: auto;
    }

    div[lay-id="saleOrderTable"] .layui-table-cell,
    div[lay-id="saleOrderTable"] .layui-form,
    div[lay-id="saleOrderTable"] .layui-table-box,
    div[lay-id="saleOrderTable"] .layui-table-body {
        overflow: visible;
    }

    div[lay-id="deliverProductTable"] td[data-field="productPack"] .layui-table-cell,
    div[lay-id="deliverProductTable"] .layui-form,
    div[lay-id="deliverProductTable"] .layui-table-box,
    div[lay-id="deliverProductTable"] .layui-table-body {
        overflow: visible;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <form class="layui-form">
                <div class="layui-form lay-header">
                    <div class="toolbar">
                        <div class="layui-form-item lay-query-content">
                            <div class="lay-query-box">
                                <div class="query-lt">
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">计划单编号：</label>
                                        <div class="layui-input-inline">
                                            <input name="code" class="layui-input" type="text"
                                                   placeholder="计划单编号"/>
                                        </div>
                                    </div>
                                    <!--<div class="layui-inline">
                                        <label class="layui-form-label w-auto">出库类型：</label>
                                        <div class="layui-input-inline mr0">
                                            <select name="inoutTypeCode" lay-filter="inoutTypeCode">
                                            </select>
                                        </div>
                                    </div>-->
<!--                                    <div class="layui-inline">-->
<!--                                        <label class="layui-form-label w-auto">按发货仓：</label>-->
<!--                                        <div class="layui-input-inline">-->
<!--                                            <select name="outWarehouseId" lay-filter="outWarehouseId"-->
<!--                                                    id="outWarehouseNameSelect">-->
<!--                                                <option value="">按发货仓</option>-->
<!--                                            </select>-->
<!--                                        </div>-->
<!--                                    </div>-->

                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">创建时间：</label>
                                        <div class="layui-input-inline">
                                            <input id="pTime" class="layui-input date-icon" type="text"
                                                   placeholder="选择创建时间" autocomplete="off" readonly/>
                                        </div>
                                        <input name="startCreateTime" id="sTime" style="display:none"/>
                                        <input name="endCreateTime" id="eTime" style="display:none"/>
                                    </div>
                                    <div class="layui-inline">
                                        <button type="button" id="deliverySearch" class="layui-btn icon-btn color-green"
                                                lay-filter="deliveryPlanSearch" lay-submit>查询
                                        </button>
                                        <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                                            重置
                                        </button>
                                    </div>
                                </div>
                                <div class="query-rt"></div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button type="button" id="deliveryPlanBtnAdd" class="layui-btn icon-btn color-reseda">
                                    添加订单交付计划
                                </button>
                            </div>
                            <div class="lay-btn-rt">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 表格 -->
            <table class="layui-table" id="deliveryPlanTable" lay-filter="deliveryPlanTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="deliveryPlanTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
    {{# if(d.status =="confirmed"){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="audit">审核</a>
    {{# } }}
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="deliveryPlanForm">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <form lay-filter="deliveryPlanForm" id="deliveryPlanForm2" class="layui-form model-form"
                      style="padding: 0px 10px 0px 0px">
                    <input name="id" type="hidden"/>
                    <input name="inoutTypeCode" value="marketdOut" type="hidden"/>
                    <div class="layui-row table-bor" style="margin-top: 20px">
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">销售类型</label>
                            <div class="layui-input-inline">
                                <select name="salesType" id="salesType" lay-filter="salesType" lay-verify="required"
                                        style="text-align: center;"
                                        class="setSelectDisabled">
                                    <option value="">请选择订单类型</option>
                                    <option value="rawMaterial">原材料销售</option>
                                    <option value="finished">成品销售</option>
                                    <option value="waste">废品销售</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">选择仓库</label>
                            <div class="layui-input-inline">
                                <select name="outWarehouseId" id="outWarehouseOption" required lay-verify="required"
                                        style="text-align: center;"
                                        placeholder="请选择出货仓库" class="setSelectDisabled"></select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">交付时间</label>
                            <div class="layui-input-inline">
                                <input type="text" style="width: 150px" name="sendTime" id="sendTime"
                                       style="text-align: center;"
                                       placeholder="请选择发货时间" autocomplete="off"
                                       class="layui-input setInputDisabled">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">客户</label>
                            <div class="layui-input-inline">
                                <select name="customerId" id="customerId" lay-filter="customerId"
                                        style="text-align: center;"
                                        lay-verify="required" class="setSelectDisabled"></select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">销售订单</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="saleOrderId"/>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">客户联系人</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="contactName"/>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">销售部门</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="department"/>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">销售员</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="salesmanName"/>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3">
                            <label class="layui-form-label">订单审核人</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="approverName"/>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item text-left" style="margin-top: 20px;">
                        <button id="deliveryProductBtnAdd" type="button" class="layui-btn icon-btn">
                            添加销售物料
                        </button>
                    </div>
                    <div class="layui-row table-bor" style="margin-top: 20px">
                        <table class="layui-table" id="deliverProductTable" lay-filter="deliverProductTable"></table>
                    </div>

                    <div class="layui-form-item text-center" style="margin-left: 134px;">
                        <button class="layui-btn" id="deliveryPlanFormSubmit" lay-filter="deliveryPlanFormSubmit"
                                lay-submit>确认交付计划
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</script>

<!--包装方式下拉框-->
<script type="text/html" id="packingTemplet">
    <select name="productPack" id="productPack" class="productPack" lay-filter="productPack"
            lay-verify="required"></select>
</script>

<!--交付商品信息-->
<script type="text/html" id="deliveryPlanProductForm">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <select name="productTypeId" lay-filter="productTypeId" id="productTypeId">
                                <option value="">类型</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <select name="productCategoryId" lay-filter="productCategoryId" id="productCategoryId">
                                <option value="">物料分类</option>
                            </select>
                        </div>

                        <div class="layui-inline">
                            <input name="skuSpecValueNames" class="layui-input" type="text" placeholder="规格码"/>
                        </div>
                        <div class="layui-inline">
                            <input name="productName" class="layui-input" type="text" placeholder="物料名称"/>
                        </div>
                        <div class="layui-inline">
                            <input name="skuCode" class="layui-input" type="text" placeholder="物料编号"/>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-submit=""
                                    lay-filter="productSearch"><i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                </form>
                <table class="layui-table" id="productTable" lay-filter="productTable" style="height: 0px"></table>
                <div class="layui-form-item" style="margin-top: 10px;text-align: center;">
                    <div class="layui-inline">
                        <button id="productConfirmBtn" type="button" lay-event="getCheckData"
                                class="layui-btn icon-btn">确定提交
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>
<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;
        var type = 0; //0是添加 1是详情
        var productSkuCodeArr = [];
        var deliverProductList = [];//出库物料数据
        var outData = null;
        var detailData = null;
        var inWarehouseName = "";
        //日期范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    let dateValue = value.split(" - ");
                    $("input[name='startCreateTime']").val(dateValue[0] + " 00:00:00");
                    $("input[name='endCreateTime']").val(dateValue[1] + " 23:59:59");
                } else {
                    $("input[name='startCreateTime']").val("");
                    $("input[name='endCreateTime']").val("");
                }
            }
        });

        // option渲染
        function loadSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].productType}'>${data[i].name}</option>`;
                } else if (type == 2) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type == 3) {
                    html += `<option value='${data[i].id}'>${data[i].warehouseName}</option>`;
                } else if (type == 4) {
                    html += `<option value='${data[i].skuCode}'  skuCode='${data[i].skuCode}'>${data[i].skuName}</option>`;
                } else if (type == 5) {
                    html += `<option value='${data[i].skuCode}'>${data[i].skuName}</option>`;
                } else if (type == 6) {
                    html += `<option value='${data[i].code}'>${data[i].name}</option>`;
                } else if (type == 7) {
                    html += `<option value='${data[i].id}'>${data[i].customerName}</option>`;
                } else if (type == 8) {
                    html += `<option baseRate='${data[i].baseRate}' value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type == 9) {
                    html += `<option value='${data[i].id}'>${data[i].code}</option>`;
                }

            }

            $("form select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        //查询仓库
        admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
            if (res.code == 200) {
                if (res.data.length > 0) {
                    $.each(res.data, function (index, item) {
                        $("#outWarehouseNameSelect").append(new Option(item.name, item.id));
                    })
                    $.each(res.data, function (index, item) {
                        $("#inWarehouseNameSelect").append(new Option(item.name, item.id));
                    })
                    form.render('select');
                }
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');

        // 渲染表格
        var insTb = table.render({
            elem: '#deliveryPlanTable',
            url: config.base + 'enterprisecab/order/admin/inventoryOutPlan/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            where: {inoutTypeCode: "marketdOut"},
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'}
                , {field: 'code', align: 'center', title: '出库计划单编号', width: 150}
                , {field: 'outWarehouseName', align: 'center', title: '发货仓库'}
                , {field: 'consigner', align: 'center', title: '发货人', width: 130}
                , {field: 'quantityTotal', align: 'center', title: '出库商品数量', width: 130}
                , {field: 'marketAmount', align: 'center', title: '市场总价', width: 130}
                , {field: 'supplyAmount', align: 'center', title: '总供货金额'}
                , {field: 'inWarehouseName', align: 'center', title: '入库云仓'}
                , {field: 'customerConcat', align: 'center', title: '联系人'}
                , {field: 'inAreaName', align: 'center', title: '仓库所在地'}
                , {field: 'statusDesc', align: 'center', title: '状态'}
                , {field: 'createTime', align: 'center', title: '添加时间', width: 160}
                , {align: 'center', toolbar: '#deliveryPlanTableBar', title: '操作', width: 150}
            ]],
            done: function (res, curr, count) {

            }
        });
        form.render('select');
        // 工具条点击事件
        table.on('tool(deliveryPlanTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'details') { //详情
                type = 1;
                outData = data;
                /* showEditModel(type,outData);*/

                admin.req('enterprise/sell/admin/deliveryPlan/getDeliveryPlanDetailList', {deliveryPlanId: data.selDeliveryId}, function (res) {
                    detailData = res.data;
                    showEditModel(type, outData, detailData);
                }, 'GET');

            } else if (obj.event === 'audit') { // 审核
                doDelete(obj);
            }
        });

        //监听排序
        table.on('sort(deliveryPlanTable)', function (obj) {
            table.reload('deliveryPlanTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(deliveryPlanSearch)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
            return false;
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#deliveryPlanBtnAdd').click(function () {
            type = 0;
            outData = null;
            showEditModel(type, outData);
        });

        // 显示编辑弹窗
        function showEditModel(type, data, detailData) {
            admin.formOpen({
                area: ['80%', '800px'],
                offset: ['50px', '10%'],
                title: data ? '交付计划详情' : '添加交付计划',
                path: 'components/sell/deliveryPlanForm.html',
                success: function () {
                    parentData.data = data
                }
            })
            // admin.open({
            //     type: 1,
            //     area: ['80%', '800px'],
            //     offset: ['50px', '10%'],
            //     title: data ? '交付计划详情' : '添加交付计划',
            //     content: $('#deliveryPlanForm').html(),
            //     success: function (data) {
            //         //查询仓库
            //         if(data.id){
            //
            //         }else{
            //             admin.initDataSelect('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll',{},'outWarehouseOption',null,'出货仓库')
            //             admin.initDataSelect('enterprise/sell/admin/customersInfo/list',{},'customerId',null,'客户')
            //             // admin.req('enterprise/sell/admin/customersInfo/list', {}, function (res) {
            //             //     if (res.code == 200) {
            //             //         // loadSelectHtml(res.data, '请选择客户', 'customerId', 7);
            //             //         // admin.initDataSelect(res.data,{},'customerId',null,'客户')
            //             //
            //             //         console.log('data',res.data)
            //             //         form.on('select(customerId)', function (data) {
            //             //             admin.req('enterprise/sell/admin/customersInfo/list', {id: data.value}, (res) => {
            //             //                 if (res.code == '200') {
            //             //                     /*$("#contactName").val(res.data[0].contactName);
            //             //                     $("#department").val(res.data[0].department);
            //             //                     $("#salesperson").val(res.data[0].salesmanName);
            //             //                     $("#approverName").val(res.data[0].approverName);*/
            //             //                     form.val('deliveryPlanForm', res.data[0]);
            //             //                 }
            //             //             }, 'get');
            //             //         });
            //             //         // if (detailData) {
            //             //         //     $("#customerId").val(detailData[0].customerId);
            //             //         //     form.render('select');
            //             //         //     admin.req('enterprise/sell/admin/customersInfo/list', {id: detailData[0].customerId}, (res) => {
            //             //         //         if (res.code == '200') {
            //             //         //             form.val('deliveryPlanForm', res.data[0]);
            //             //         //         }
            //             //         //     }, 'get');
            //             //         // }
            //             //     } else {
            //             //         layer.msg('获取客户失败', {icon: 2, time: 1000});
            //             //     }
            //             // }, 'GET');
            //         }
            //
            //
            //
            //
            //         if (detailData) {
            //             var option = $("form select[name='salesType']").find("option");
            //             layui.each(option, function (index, item) {
            //                 if (data.job == item.text) {
            //                     data.job = item.value;
            //                 }
            //             });
            //         }
            //         //获取销售订单
            //         admin.req('enterprise/sell/admin/deliveryRecord/getSaleOrderInfo', {limit: 9999}, function (res) {
            //             if (res.code == 200) {
            //                 loadSelectHtml(res.data, '请选择销售订单', 'saleOrderId', 9);
            //                 if (detailData) {
            //                     $("#saleOrderId").val(detailData[0].saleOrderId);
            //                     form.render('select');
            //                 }
            //             } else {
            //                 layer.msg('获取订单失败', {icon: 2, time: 1000});
            //             }
            //         }, 'GET');
            //
            //         if (type == 1) {//详情
            //             //出货商品详情
            //             //enterprisecab/order/admin/inventoryOutPlan/getInventoryOutPlanDetailVOList
            //             if (data) {
            //
            //                 admin.req('enterprise/sell/admin/deliveryPlan/getDeliveryPlanDetailList', {deliveryPlanId: data.selDeliveryId}, function (res) {
            //                     if (res.code == 200) {
            //                         $("#salesType").val(res.data[0].salesType);
            //                         form.render('select');
            //
            //                         deliverProductList = res.data;
            //                         table.reload('deliverProductTable', {
            //                             data: deliverProductList,
            //                         })
            //                     } else {
            //                         layer.msg(res.msg, {icon: 2});
            //                     }
            //                 }, 'GET');
            //             }
            //             //设置禁用
            //             /*$("#salesType").attr("disabled", "disabled");
            //             $("#customerId").attr("disabled", "disabled");
            //             $("#outWarehouseOption").attr("disabled", "disabled");
            //             $("#saleOrderId").attr("disabled", "disabled");
            //             $("#sendTime").attr("disabled", "disabled");
            //             $("#sendTime").attr("style", "background-color: #EEEEEE;width: 150px");//设置input为灰色背景*/
            //             //设置下拉框禁用
            //             $(".setSelectDisabled").attr("disabled", "disabled");
            //             //设置input禁用
            //             $(".setInputDisabled").attr("disabled", "disabled");
            //             $(".setInputDisabled").attr("style", "background-color: #EEEEEE;width: 150px");//设置input为灰色背景
            //
            //             //设置添加物料按钮禁用
            //             $("#deliveryProductBtnAdd").attr("disabled", true);
            //
            //             //隐藏提交按钮
            //             $("#deliveryPlanFormSubmit").hide();
            //
            //         }
            //
            //         deliverProductList = [];//每次打开弹框清空出库物料数据
            //         //发货时间
            //         laydate.render({
            //             elem: '#sendTime'
            //             , type: 'datetime'
            //         });
            //
            //
            //         //添加出库商品点击事件
            //         $("#deliveryProductBtnAdd").click(function () {
            //             showProductModel();
            //         })
            //         var deliverProductTable = table.render({
            //             elem: '#deliverProductTable',
            //             data: deliverProductList,
            //             cellMinWidth: 100,
            //             cols: [[
            //                 {field: 'number', title: '序号', type: 'numbers'}
            //                 , {field: 'id', title: 'ID', hide: true}
            //                 , {
            //                     field: 'skuPic',
            //                     align: 'center',
            //                     title: '图片',
            //                     width: 100,
            //                     hide: type == 0 ? true : false
            //                     ,
            //                     templet: '<div><img  src="{{ d.skuPic }}"></div>'
            //                 }
            //                 , {
            //                     field: 'productPic',
            //                     sort: true,
            //                     title: '图片',
            //                     width: 100,
            //                     hide: type == 1 ? true : false
            //                     ,
            //                     templet: '<div><img  src="{{ d.productPic }}"></div>'
            //                 }
            //                 , {field: 'skuCode', align: 'center', title: '物料编号'}
            //                 // , {field: 'skuSpecValueNames', title: 'SKU规格',hide : type == 1 ? true : false}
            //                 , {field: 'skuSpecCode', align: 'center', title: '规格码', hide: type == 0 ? true : false}
            //                 , {field: 'productTypeName', align: 'center', title: '物料类型'}
            //                 , {field: 'marketPrice', align: 'center', title: '物料单价'}
            //                 , {field: 'unitName', align: 'center', title: '计价单位'}
            //                 , {field: '', align: 'center', title: '订单数量'}
            //                 , {
            //                     field: 'planQuantity', align: 'center', title: '本次发货数量', align: 'center',
            //                     templet: d => '<input type="text" lay-verify="required" id="planQuantity" value="' + d.quantity + '" class="layui-input planQuantity" />'
            //                 }
            //                 , {
            //                     field: 'subtotalAmount', align: 'center', title: '小计金额',
            //                     templet: d => '￥<span class="subtotalAmount" id="subtotalAmount" ></span>'
            //                 }
            //                 , {
            //                     field: 'packUnit', align: 'center', title: '包装单位',
            //                     templet: d => '<span class="packUnit" id="packUnit" ></span>'
            //                 }
            //                 , {field: 'productPack', align: 'center', title: '包装方式', templet: "#packingTemplet"}
            //                 , {
            //                     field: 'packNum', align: 'center', title: '包装数量',
            //                     templet: d => '<span class="packNum" id="packNum"></span>'
            //                 }
            //
            //             ]]
            //             , done: function (res, curr, count) {
            //
            //                 //获取包装方案
            //                 admin.req('enterprise/product/admin/productPack/getAll', {}, function (res) {
            //                     loadSelectHtml(res.data, "请选择", "productPack", 8);
            //                     if (detailData) {
            //                         for (let i = 0; i < detailData.length; i++) {//赋值
            //                             $(".layui-table-box tbody tr[data-index='" + i + "'] td[data-field='productPack'] .productPack").val(detailData[i].packId);
            //                             form.render('select');
            //
            //                             //获取包装单位
            //                             admin.req('supplier/product/admin/productPack/getPackUnit', {id: detailData[i].packId}, function (res) {
            //                                 if (res.code == 200) {
            //                                     $(".layui-table-box tbody tr[data-index='" + i + "'] td[data-field='packUnit'] .packUnit").text(res.data.packUnitName);
            //                                 }
            //                             });
            //
            //                             $(".layui-table-box tbody tr[data-index='" + i + "'] td[data-field='subtotalAmount'] .subtotalAmount").text(detailData[i].subtotalAmount);
            //                             $(".layui-table-box tbody tr[data-index='" + i + "'] td[data-field='packNum'] .packNum").text(detailData[i].packNum);
            //                         }
            //
            //                         //禁用
            //                         $(".planQuantity").attr("disabled", "disabled");
            //                         $(".productPack").attr("disabled", "disabled");
            //
            //                         $(".planQuantity").attr("style", "background-color: #EEEEEE;");//设置input为灰色背景
            //                     }
            //                 }, 'get');
            //
            //                 $("body").delegate(".planQuantity", "change", function () {
            //                     if ($(this).val() <= 0) {
            //                         $(this).val(deliverProductList[$(this).parents('tr').index()].inventory)
            //                     }
            //                     let mPrice = $(this).parents('tr').find('td[data-field="marketPrice"]').text();
            //                     $(this).parents('tr').find('.subtotalAmount').text(mPrice * $(this).val());
            //
            //                     deliverProductList[$(this).parents('tr').index()].quantity = $(this).val();
            //                     deliverProductList[$(this).parents('tr').index()].subtotalAmount = $(this).parents('tr').find('.subtotalAmount').text();
            //                 });
            //
            //                 form.on('select(productPack)', data => {
            //                     //获取包装单位
            //                     admin.req('enterprise/product/admin/productPack/getPackUnit', {id: data.value}, function (res) {
            //                         if (res.code == 200) {
            //                             var unitData = res.data;
            //                             var packUnitName = unitData.packUnitName;
            //                             if (packUnitName == null) {
            //                                 $(data.elem).parents('tr').find('.packUnit').text('');
            //                             } else {
            //                                 $(data.elem).parents('tr').find('.packUnit').text(packUnitName);
            //                             }
            //
            //                         }
            //
            //                     }, 'get')
            //                     let planQuantity = $(data.elem).parents('tr').find('.planQuantity').val();
            //                     let baseRate = $(data.elem[data.elem.selectedIndex]).attr('baseRate');
            //                     let packNum = Math.ceil(planQuantity / baseRate);
            //                     $(data.elem).parents('tr').find('.packNum').text(packNum);
            //
            //                     deliverProductList[$(data.elem).parents('tr').index()].packNum = packNum;
            //                     deliverProductList[$(data.elem).parents('tr').index()].packName = data.elem[data.elem.selectedIndex].text;
            //
            //                     deliverProductList[$(data.elem).parents('tr').index()].baseRate = $(data.elem[data.elem.selectedIndex]).attr('baseRate');
            //                     deliverProductList[$(data.elem).parents('tr').index()].packId = data.value
            //                 });
            //
            //             }
            //         });
            //
            //
            //         form.val('deliveryPlanForm', data);
            //         // 表单提交事件
            //         form.on('submit(deliveryPlanFormSubmit)', function (d) {
            //
            //             if (deliverProductList.length == 0) {
            //                 layer.msg("请先添加出库商品", {icon: 2});
            //                 return false;
            //             }
            //
            //             /*console.log("状态",data.status)
            //             if(data.status != 'confirmed'){
            //                 layer.msg("此出库计划已经审核，不能再次提交",{icon: 2});
            //                 return false;
            //             }*/
            //
            //             d.field.productJson = JSON.stringify(deliverProductList);
            //
            //             layer.load(2);
            //             //
            //             admin.req('enterprise/sell/admin/deliveryPlan/add', d.field, function (res) {
            //                 layer.closeAll('loading');
            //                 if (res.code == 200) {
            //                     layer.msg(res.msg, {icon: 1});
            //                     table.reload('deliveryPlanTable');
            //                     layer.closeAll('page');
            //                 } else {
            //                     layer.msg(res.msg, {icon: 2});
            //                 }
            //             }, 'POST');
            //
            //             return false;
            //         });
            //     }
            // });
        }

        //enterprise/product/admin/productPackLabel/getProductPackLabelVOList
        function showProductModel() {
            var index = admin.open({
                type: 1,
                area: ['1550px', '800px'],
                offset: ['80px', '300px'],
                title: '添加交付计划商品信息',
                content: $('#deliveryPlanProductForm').html(),
                success: function () {
                    form.render('select');
                    var productTable = table.render({
                        elem: '#productTable',
                        url: config.base + 'enterprise/product/admin/productDetail/getProductDetailPageList',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            // , {field: 'number', align:'center',title: '序号', width: 60, type: 'numbers'}
                            , {
                                field: 'productPic',
                                align: 'center',
                                title: '图片',
                                width: 100,
                                templet: '<div><img src="{{ d.productPic}}" style="height: 80px;width: 80px;"></div>'
                            }
                            , {field: 'productName', align: 'center', title: '物料名称', width: 120}
                            , {field: 'skuCode', align: 'center', title: '物料编号', width: 150}
                            , {field: 'skuSpecValueNames', align: 'center', title: '规格码'}
                            , {field: 'productTypeName', align: 'center', title: '物料类型'}
                            , {field: 'companyName', align: 'center', title: '制造企业'}
                            , {field: 'weightNumber', align: 'center', title: '重量'}
                            , {
                                field: 'deleted',
                                align: 'center',
                                title: '状态',
                                templet: d => d.deleted ? '已删除' : '正常'
                            }
                            , {field: 'unitName', align: 'center', title: '计价单位'}
                            , {field: 'createTime', align: 'center', title: '发布时间', width: 160}
                            , {field: 'updateTime', align: 'center', title: '变动时间', width: 170}
                        ]]
                    });
                    //查询物料类型
                    admin.req('enterprise/product/admin/productType/getProductTypeVOAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                $.each(res.data, function (index, item) {
                                    $("#productTypeId").append(new Option(item.name, item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                    //查询物料分类
                    admin.req('enterprise/product/admin/productCategory/getAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                $.each(res.data, function (index, item) {
                                    $("#productCategoryId").append(new Option(item.name, item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');

                    // 搜索
                    form.on('submit(productSearch)', function (data) {
                        productTable.reload({where: data.field, page: {curr: 1}}, 'data');
                        return false;
                    });
                    $("#productConfirmBtn").click(function () {
                        //头工具栏事件
                        var checkRows = table.checkStatus('productTable');
                        if (checkRows.data.length == 0) {
                            layer.msg('请选择要确认出货的商品', {icon: 2});
                            return;
                        }
                        let flag = false;
                        // 确认出货的商品
                        checkRows.data.forEach((item, index) => {
                            const row = deliverProductList.find(x => x.skuCode === item.skuCode);
                            checkRows.data[index].quantity = 1;
                            if (row) {
                                flag = true;
                                layer.msg('选择发货的商品中有重复存在的，请检查', {icon: 2});
                            }
                        })

                        if (!flag) {
                            deliverProductList.push(...checkRows.data)
                            //确认提交物料信息，重载deliverProductList
                            table.reload('deliverProductTable', {
                                data: deliverProductList,
                            })
                            layer.close(index);
                        }

                        /*admin.req('enterprisecab/order/admin/inventoryOutPlan/getProductDetailList', {productSkuCodeArr: productSkuCodeArr}, function (res) {
                            if (res.code == 200) {
                                deliverProductList = res.data;
                                for (let i = 0; i < deliverProductList.length; i++) {
                                    deliverProductList[i].quantity = 1;
                                }
                                //确认提交物料信息，重载deliverProductList
                                table.reload('deliverProductTable',{
                                    data: deliverProductList,
                                })
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');*/
                    })

                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要审核吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/order/admin/inventoryOutPlan/updateStatus', {id: obj.data.id}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('deliveryPlanTable', {})
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'PUT');
            });
        }

        // 导出excel
        $('#inventoryOutPlanBtnExport').click(function () {
            var checkRows = table.checkStatus('deliveryPlanTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>